<?php

$array = array();

foreach ($data['fields'] as $row)
{
    foreach($row as $field)
        {
            if(!isset($field['catcategories_code']))
                {
                    $value_ = getMatchData($data['fieldDB'], $data['match'], $field['cateventsdbfields_id']);
                    $aux = array(
                                "id" => $field['id'],
                                "name" => $field['name'],
                                "order" => $field['order'],
                                "type" => $field['type'],
                                "cateventstype_id" => $field['cateventstype_id'],
                                "value" => $value_
                            );
                    array_push($array, $aux);
                }
        }
}
echo json_encode($array);


function getMatchData($DBFields, $match, $idFieldDB)
{
    if($idFieldDB == 0)
    {return "";}
    else
    {
        $fieldName = "";
        foreach($DBFields as $db_f)
        {
            if($db_f['EventsDBFields']['id'] == $idFieldDB)
            {
                $fieldName = $db_f['EventsDBFields']['dbname'];
                break;
            }
        }
        
        if($fieldName != "")
        {$fieldName = $match['TurnamentMatchs'][$fieldName];}
        return $fieldName;
    }
}
?>